import type { Ref } from 'vue'
import type {
  BaseTableOperations,
  TableRefType,
  TableType,
} from '@/types/components/tableTypes.js'
import { ref } from 'vue'
import {
  createTableAdapter,
  getTableType,
} from '@/types/components/tableTypes.js'

export function useTableOperations(tableRef: Ref<TableRefType>) {
  const tableAdapter = ref<BaseTableOperations | null>(null)
  const currentTableType = ref<TableType | null>(null)

  const initTable = () => {
    tableAdapter.value = createTableAdapter(tableRef.value)
    currentTableType.value = getTableType(tableRef.value)
  }

  return {
    currentTableType,
    initTable,
  }
}
